package com.ayuku.commons;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.logging.Logger;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;

/**
 * 
 * @author putu kusuma <putukn@gmail.com>
 *
 */
public abstract class ListFormMasterWShort extends
		org.eclipse.swt.widgets.Dialog {
	protected Shell dialogShell;
	protected Table tableData = null;
	private Button btnFind;
	private Label lblMessage;
	private Button btnHelp;
	private Button btnClear;
	private Label lblRecordMsg;
	private Label lblSearch;
	private Text fSearch;
	private Button btnReload;
	protected Button btnDelete;
	private Button btnEdit;
	protected Button btnNew;
	private Composite pnlButtonCmd;
	private Composite pnlData;
	private Composite pnlSearch;
	private String funcId;
	protected Button btnExport;
	protected Object[][] data;

	public String getFuncId() {
		return funcId;
	}

	public void setFuncId(String funcId) {
		this.funcId = funcId;
	}

	private Logger LOG = Logger.getLogger(ListFormMasterWShort.class.getName());

	public ListFormMasterWShort(final Shell parent, final int style) {
		super(parent, style);
	}

	public final void open() {
		try {
			data = new Object[10][];
			final Shell parent = getParent();
			dialogShell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE);
		

			final FormLayout dialogShellLayout = new FormLayout();
			dialogShell.addKeyListener(new KeyAdapter() {
				public void keyPressed(KeyEvent evt) {
					dialogShellKeyPressed(evt);
				}
			});
			dialogShell.setBackground(SWTResourceManager
					.getColor(171, 209, 252));

			dialogShell.setLayout(dialogShellLayout);
			dialogShell.layout();
			dialogShell.pack();
			dialogShell.setSize(757, 412);
			dialogShell.setText("Test");
			dialogShell.setLocation(60, 100);

			pnlButtonCmd = new Composite(dialogShell, SWT.NONE);

			FillLayout composite3Layout = new FillLayout(
					org.eclipse.swt.SWT.HORIZONTAL);
			composite3Layout.spacing = 2;
			pnlButtonCmd.setLayout(composite3Layout);

			FormData pnlButtonLData = new FormData();
			pnlButtonLData.width = 370;
			pnlButtonLData.height = 32;
			pnlButtonLData.left = new FormAttachment(0, 1000, 4);
			pnlButtonLData.top = new FormAttachment(0, 1000, 6);
			pnlButtonCmd.setLayoutData(pnlButtonLData);
			pnlButtonCmd.setBackground(SWTResourceManager.getColor(171, 209,
					252));
			btnNew = new Button(pnlButtonCmd, SWT.PUSH | SWT.CENTER);
			btnNew.setAlignment(SWT.CENTER);
			btnNew.setToolTipText("Tombol 'Tambah' untuk menambah data baru");

			btnNew.setImage(SWTResourceManager.getImage(ListFormMasterWShort.class, "/images/form/database_add.png"));
			btnNew.setSize(34, 34);
			btnNew.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
			btnNew.setBackground(SWTResourceManager.getColor(171, 209, 252));
			btnNew.setText("Tambah");
			btnNew.setFont(SWTResourceManager.getFont("Arial", 8, 0, false,
					false));
			btnNew.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent evt) {
					btnNewWidgetSelected(evt);
				}
			});
			btnEdit = new Button(pnlButtonCmd, SWT.PUSH | SWT.CENTER);

			btnEdit.setToolTipText("Tombol 'View' untuk menampilkan detail baris yang dipilih.");
			btnEdit.setImage(SWTResourceManager.getImage(ListFormMasterWShort.class, "/images/form/zoom.png"));
			btnEdit.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
			btnEdit.setSize(34, 34);
			btnEdit.setBackground(SWTResourceManager.getColor(171, 209, 252));
			btnEdit.setText("Edit");
			btnEdit.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent evt) {
					btnEditWidgetSelected(evt);
				}
			});
			btnDelete = new Button(pnlButtonCmd, SWT.PUSH | SWT.CENTER);

			btnDelete
					.setToolTipText("Tombol 'Hapus' untuk menghapus data yg dipilih.");
			btnDelete.setImage(SWTResourceManager.getImage(ListFormMasterWShort.class, "/images/form/database_delete.png"));
			btnDelete.setSize(34, 34);
			btnDelete.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
			btnDelete.setBackground(SWTResourceManager.getColor(171, 209, 252));
			btnDelete.setText("Hapus");
			btnDelete.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent evt) {
					btnDeleteWidgetSelected(evt);
				}
			});
			btnReload = new Button(pnlButtonCmd, SWT.PUSH | SWT.CENTER);
			btnReload
					.setToolTipText("Tombol 'Refresh' untuk merefresh/mereload data terbaru dari database ");

			btnReload.setImage(SWTResourceManager.getImage(ListFormMasterWShort.class, "/images/form/database_refresh.png"));
			btnReload.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
			btnReload.setBackground(SWTResourceManager.getColor(171, 209, 252));
			btnReload.setText("Reload");

			btnExport = new Button(pnlButtonCmd, SWT.PUSH | SWT.CENTER);
			btnExport.setImage(SWTResourceManager
					.getImage("images/form/page_excel.png"));

			btnExport.setBackground(SWTResourceManager.getColor(171, 209, 252));
			btnExport
					.setToolTipText("Tombol 'Help' untuk menampilkan petunjuk lebih lengkap");
			btnExport.setText("Export");
			btnExport.addSelectionListener(new SelectionAdapter() {

				public void widgetSelected(SelectionEvent evt) {
					btnExportWidgetSelected(evt);
				}
			});

			btnReload.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent evt) {
					btnReloadWidgetSelected(evt);
				}
			});

			pnlSearch = new Composite(dialogShell, SWT.NONE);
			pnlSearch.setLayout(new GridLayout(5, false));

			FormData pnlSearchLData = new FormData();
			pnlSearchLData.width = 749;
			pnlSearchLData.height = 35;
			pnlSearchLData.left = new FormAttachment(0, 1000, 0);
			pnlSearchLData.top = new FormAttachment(0, 1000, 42);
			pnlSearchLData.right = new FormAttachment(1000, 1000, 0);
			pnlSearch.setLayoutData(pnlSearchLData);
			pnlSearch.setBackground(SWTResourceManager.getColor(191, 211, 249));
			lblSearch = new Label(pnlSearch, SWT.NONE);
			lblSearch.setText("Search :");

			lblSearch.setAlignment(SWT.RIGHT);

			lblSearch.setBackground(SWTResourceManager.getColor(191, 211, 249));
			fSearch = new Text(pnlSearch, SWT.SEARCH);
			fSearch.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false,
					1, 1));
			fSearch.setMessage("search");
			// fSearch.setText("");

			fSearch.setToolTipText("Kotak 'Pencarian' ketikkan data yang akan di cari di kotak ini kemudian tekan enter atau tekan tombol 'Pencarian'");
			fSearch.addKeyListener(new KeyAdapter() {
				public void keyReleased(KeyEvent evt) {
					fSearchKeyReleased(evt);
				}
			});
			btnFind = new Button(pnlSearch, SWT.PUSH | SWT.CENTER);

			btnFind.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
			btnFind.setBackground(SWTResourceManager.getColor(191, 211, 249));

			btnFind.setToolTipText("Tombol 'Search' tekan tombol ini untuk memulai pencarian data");
			btnFind.setText(" Go ");
			btnFind.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent evt) {
					btnFindWidgetSelected(evt);
				}
			});
			btnClear = new Button(pnlSearch, SWT.PUSH | SWT.CENTER);

			btnClear.setBackground(SWTResourceManager.getColor(191, 211, 249));

			btnClear.setToolTipText("Tombol 'Clear search' untuk menghapus kriteria pencarian yang diketikkan di kotak pencarian dan menampilkan data tanpa kriteria.");
			btnClear.setText("Reset");
			btnClear.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent evt) {
					btnClearWidgetSelected(evt);
				}
			});
			lblRecordMsg = new Label(pnlSearch, SWT.NONE);
			lblRecordMsg.setAlignment(SWT.RIGHT);

			lblRecordMsg.setBackground(SWTResourceManager.getColor(192, 192,
					192));

			pnlData = new Composite(dialogShell, SWT.NONE);

			final FillLayout composite2Layout = new FillLayout(
					org.eclipse.swt.SWT.HORIZONTAL);
			composite2Layout.marginHeight = 6;
			composite2Layout.marginWidth = 6;
			pnlData.setLayout(composite2Layout);

			final FormData pnlDataLData = new FormData();
			pnlDataLData.width = 749;
			pnlDataLData.height = 280;
			pnlDataLData.left = new FormAttachment(0, 1000, 0);
			pnlDataLData.top = new FormAttachment(0, 1000, 77);
			pnlDataLData.right = new FormAttachment(1000, 1000, 0);
			pnlDataLData.bottom = new FormAttachment(1000, 1000, -21);
			pnlData.setLayoutData(pnlDataLData);
			pnlData.setBackground(SWTResourceManager.getColor(171, 209, 252));
			tableData = new Table(pnlData, SWT.VIRTUAL | SWT.MULTI
					| SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL
					| SWT.H_SCROLL);

			tableData.addKeyListener(new KeyAdapter() {
				public void keyPressed(KeyEvent evt) {
					tableDataKeyPressed(evt);
				}
			});

			tableData.addMouseListener(new MouseAdapter() {
				public void mouseDoubleClick(MouseEvent evt) {
					tableDataMouseDoubleClick(evt);
				}
			});

			lblMessage = new Label(dialogShell, SWT.NONE);

			FormData lblMessageLData = new FormData();
			lblMessageLData.left = new FormAttachment(0, 1000, 7);
			lblMessageLData.width = 649;
			lblMessageLData.height = 18;
			lblMessageLData.bottom = new FormAttachment(1000, 1000, -3);
			lblMessageLData.right = new FormAttachment(1000, 1000, -93);
			lblMessage.setLayoutData(lblMessageLData);
			lblMessage
					.setBackground(SWTResourceManager.getColor(171, 209, 252));

			btnHelp = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
			btnHelp.setToolTipText("Tombol 'Help' untuk menampilkan petunjuk lebih lengkap");
			btnHelp.setBackground(SWTResourceManager.getColor(171, 209, 252));
			btnHelp.setImage(SWTResourceManager.getImage(ListFormMasterWShort.class, "/images/form/help.png"));
			FormData btnHelpLData = new FormData();
			btnHelpLData.width = 60;
			btnHelpLData.height = 32;
			btnHelpLData.top = new FormAttachment(0, 1000, 6);
			btnHelpLData.right = new FormAttachment(1000, 1000, -7);
			btnHelp.setLayoutData(btnHelpLData);
			btnHelp.setText("Help");
			btnHelp.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent evt) {
					btnHelpWidgetSelected(evt);
				}
			});

			final boolean dt = createTableColumn(getTableData());
			if (dt) {
				loadDataThread();
			}

			tableData.addListener(SWT.SetData, new Listener() {
				public void handleEvent(Event e) {
					TableItem item = (TableItem) e.item;
					int index = tableData.indexOf(item);
					Object[] datum = data[index];
					if (data.length > 0) {
						fillTable(datum, item);
						// item.setText((String[]) data[index]);
					}
				}
			});

			btnExport.setEnabled(false);
			btnExport.setVisible(false);

			additionalProcess();

			tableData.setFont(SWTResourceManager.getFont("Arial", 10, 0, false,
					false));

			dialogShell.setImage(SWTResourceManager.getImage(ListFormMasterWShort.class, "/images/form/application_view_tile.png"));

			// Add sort indicator and sort data when column selected
			Listener sortListener = new Listener() {
				public void handleEvent(Event e) {
					// determine new sort column and direction
					TableColumn sortColumn = tableData.getSortColumn();
					TableColumn currentColumn = (TableColumn) e.widget;
					int dir = tableData.getSortDirection();
					if (sortColumn == currentColumn) {
						dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
					} else {
						tableData.setSortColumn(currentColumn);
						dir = SWT.UP;
					}

					int s = 0;

					// sort the data based on column and direction
					for (int i = 0; i < tableData.getColumnCount(); i++) {
						if (currentColumn == tableData.getColumn(i)) {
							s = i;
						}
					}

					final int index = s;
					final int direction = dir;
					Arrays.sort(data, new Comparator<Object>() {
						public int compare(Object arg0, Object arg1) {
							Object[] a = (Object[]) arg0;
							Object[] b = (Object[]) arg1;
							if (a[index] == b[index])
								return 0;
							if (direction == SWT.UP) {

								if (a[index].getClass().equals(Integer.class)) {
									return ((Integer) a[index])
											.compareTo(((Integer) b[index])) > 0 ? -1
											: 1;
								} else if (a[index].getClass().equals(
										String.class)) {
									return ((String) a[index])
											.compareTo(((String) b[index])) > 0 ? -1
											: 1;
								} else if (a[index].getClass().equals(
										BigDecimal.class)) {
									return ((BigDecimal) a[index])
											.compareTo(((BigDecimal) b[index])) > 0 ? -1
											: 1;
								} else if (a[index].getClass().equals(
										Double.class)) {
									return ((Double) a[index])
											.compareTo(((Double) b[index])) > 0 ? -1
											: 1;
								} else if (a[index].getClass().equals(
										Boolean.class)) {
									return ((Boolean) a[index])
											.compareTo(((Boolean) b[index])) > 0 ? -1
											: 1;
								} else if (a[index].getClass().equals(
										Long.class)) {
									return ((Long) a[index])
											.compareTo(((Long) b[index])) > 0 ? -1
											: 1;
								} else {
									return ((Integer) a[index])
											.compareTo(((Integer) b[index])) > 0 ? -1
											: 1;
								}
							} else {

								if (a[index].getClass().equals(Integer.class)) {
									return ((Integer) a[index])
											.compareTo(((Integer) b[index])) < 0 ? -1
											: 1;
								} else if (a[index].getClass().equals(
										String.class)) {
									return ((String) a[index])
											.compareTo(((String) b[index])) < 0 ? -1
											: 1;
								} else if (a[index].getClass().equals(
										BigDecimal.class)) {
									return ((BigDecimal) a[index])
											.compareTo(((BigDecimal) b[index])) < 0 ? -1
											: 1;
								} else if (a[index].getClass().equals(
										Double.class)) {
									return ((Double) a[index])
											.compareTo(((Double) b[index])) < 0 ? -1
											: 1;
								} else if (a[index].getClass().equals(
										Boolean.class)) {
									return ((Boolean) a[index])
											.compareTo(((Boolean) b[index])) < 0 ? -1
											: 1;
								} else if (a[index].getClass().equals(
										Long.class)) {
									return ((Long) a[index])
											.compareTo(((Long) b[index])) < 0 ? -1
											: 1;
								} else {
									return ((Integer) a[index])
											.compareTo(((Integer) b[index])) < 0 ? -1
											: 1;
								}
							}

						}
					});

					tableData.setSortDirection(dir);
					tableData.clearAll();
				}
			};

			for (int i = 0; i < tableData.getColumnCount(); i++) {
				tableData.getColumn(i).addListener(SWT.Selection, sortListener);
			}

			dialogShell.setMinimumSize(450, 400);
			dialogShell.open();

			Display display = dialogShell.getDisplay();

			while (!dialogShell.isDisposed()) {
				if (!display.readAndDispatch()) {
					display.sleep();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			LOG.info(e.getMessage());
			Util.showMsgBox("Gagal load: " + e.getMessage(), 1,
					getDialogShell());
		}
	}

	public void loadDataThread() {
		try {
			loadSearchData();
			lblMessage.setText("Jumlah data:" + tableData.getItemCount());
		} catch (Exception e) {
			e.printStackTrace();
			Util.showMsgBox("Gagal load: " + e.getMessage(), 1,
					getDialogShell());
		}
		fSearch.setFocus();
	}

	public final boolean createTableColumn(Table tableData) {
		tableData.setLinesVisible(true);
		tableData.setHeaderVisible(true);

		boolean rtrValue = true;
		final String[] titles = getColumCaption();
		int[] col = getColumWidth();

		if (titles.length != col.length) {
			System.out
					.println("DATA JUDUL KOLOM DENGAN DATA LEBAR KOLOM TIDAK SAMA");
		}

		if (titles.length < 1) {
			rtrValue = false;
		}

		for (int i = 0; i < titles.length; i++) {
			TableColumn column = new TableColumn(tableData, SWT.NONE);
			column.setText(titles[i]);
		}

		if (col.length < 1) {
			rtrValue = false;
		}

		for (int i = 0; i < col.length; i++) {
			tableData.getColumn(i).setWidth(col[i]);
		}

		tableData.getColumn(0).setResizable(false);

		return rtrValue;
	}

	abstract protected void fillTable(Object[] obj, TableItem item);

	abstract protected String[] getColumCaption();

	abstract protected int[] getColumWidth();

	abstract protected void populateTable(String sqlDml) throws Exception;

	// abstract protected void loadAllData() throws Exception;

	// abstract protected void loadSearchData() throws Exception;

	abstract protected Integer doDelete(List<String> id) throws Exception;

	abstract protected void showEditForm();

	abstract public void printPreview();

	abstract public void showAddForm();

	abstract public void additionalProcess();

	private final void btnNewWidgetSelected(SelectionEvent evt) {

		if (!Util.isAllowedAdd(getFuncId())) {
			Util.showMsgBox("Anda tidak mempunyai hak untuk tambah data", 1,
					dialogShell);
			return;
		}

		showAddForm();
		if (Util.OPERATION_CODE > 0) {
			loadDataThread();
			Util.OPERATION_CODE = 0;
		}
		doFocusOnTableData();
	}

	private void doFocusOnTableData() {
		tableData.setFocus();
		if (tableData.getItemCount() > 0 && tableData.getSelectionCount() < 1) {
			tableData.select(0);
		}
	}

	private final void btnEditWidgetSelected(SelectionEvent evt) {
		if (!Util.isAllowedView(getFuncId())) {
			Util.showMsgBox("Anda tidak mempunyai hak untuk view data", 1,
					dialogShell);
			return;
		}
		showEditForm();
		if (Util.OPERATION_CODE > 0) {
			loadDataThread();
			Util.OPERATION_CODE = 0;
		}
		doFocusOnTableData();
	}

	private final void btnDeleteWidgetSelected(SelectionEvent evt) {

		if (!Util.isAllowedDelete(getFuncId())) {
			Util.showMsgBox("Anda tidak mempunyai hak untuk hapus data", 1,
					dialogShell);
			return;
		}

		deleteData();
		doFocusOnTableData();
	}

	private final void btnReloadWidgetSelected(SelectionEvent evt) {
		loadDataThread();
		doFocusOnTableData();
	}

	private final void btnFindWidgetSelected(SelectionEvent evt) {
		loadDataThread();
		fSearch.setFocus();
	}

	public final Shell getDialogShell() {
		return dialogShell;
	}

	public final void setDialogShell(Shell dialogShell) {
		this.dialogShell = dialogShell;
	}

	public final Table getTableData() {
		return tableData;
	}

	public void exportToExcel() {

	}

	public final void setTableData(Table tableData) {
		this.tableData = tableData;
		tableData.setFont(SWTResourceManager.getFont("Arial", 10, 0, false,
				false));
	}

	public final Text getFSearch() {
		return fSearch;
	}

	public final void setFSearch(Text search) {
		fSearch = search;
	}

	public void loadSearchData() throws Exception {
		populateTable("%" + getFSearch().getText() + "%");
	}

	public void loadAllData() throws Exception {
		populateTable("%%");
	}

	private final void tableDataMouseDoubleClick(MouseEvent evt) {
		if (!Util.isAllowedView(getFuncId())) {
			Util.showMsgBox("Anda tidak mempunyai hak untuk view data", 1,
					dialogShell);
			return;
		}

		showEditForm();
		if (Util.OPERATION_CODE > 0) {
			loadDataThread();
			Util.OPERATION_CODE = 0;
		}
	}

	private final void tableDataKeyPressed(KeyEvent evt) {
		if (evt.keyCode == 13) {
			if (!Util.isAllowedView(getFuncId())) {
				Util.showMsgBox("Anda tidak mempunyai hak untuk view data", 1,
						dialogShell);
				return;
			}

			showEditForm();
			if (Util.OPERATION_CODE > 0) {
				loadDataThread();
				Util.OPERATION_CODE = 0;
			}

		}
	}

	public final String deleteData() {
		TableItem[] items = tableData.getSelection();
		List<String> lst = new ArrayList<String>();
		if ((items == null) || (items.length < 1)) {
			Util.showMsgBox(AYConst.FAIL_DELETE, AYConst.MSG_WARN,
					getDialogShell());
		} else {

			try {
				MessageBox messageBox = new MessageBox(getDialogShell(), SWT.OK
						| SWT.CANCEL | SWT.ICON_WARNING);
				messageBox
						.setMessage("Anda Yakin akan menghapus data yang anda pilih?");
				if (messageBox.open() == SWT.OK) {

					for (int j = 0; j < items.length; j++) {
						TableItem itm = (TableItem) items[j];
						String idDelete = itm.getText(0);
						lst.add(idDelete);
					}

					if (lst.size() > 0) {
						doDelete(lst);
						loadDataThread();
					}

				}
			} catch (Exception e) {
				e.printStackTrace();

				if (e.getMessage().contains("FOREIGN KEY")) {
					Util.showMsgBox(
							"Data tidak dapat dihapus karena dipakai oleh table lain, silakan hapus terlebih dulu tabel yang pakai!, "
									+ e.getMessage(), 2, dialogShell);
				} else {
					Util.showMsgBox("Data yg dipilih gagal dihapus!, karena: "
							+ e.getMessage(), 2, dialogShell);
				}
			} finally {
				lst = null;
			}
		}

		return "success";
	}

	private void fSearchKeyReleased(KeyEvent evt) {
		if (evt.keyCode == 13) {
			loadDataThread();
		}
	}

	private void btnClearWidgetSelected(SelectionEvent evt) {
		fSearch.setText("");
		loadDataThread();
	}

	protected int rowId;

	private void btnHelpWidgetSelected(SelectionEvent evt) {
		ListHelp hlp = new ListHelp(getDialogShell(), SWT.NONE);
		hlp.open();
		doFocusOnTableData();
	}

	private void btnExportWidgetSelected(SelectionEvent evt) {
		exportToExcel();
		doFocusOnTableData();
	}

	private void dialogShellKeyPressed(KeyEvent evt) {
		System.out.println("dialogShell.keyPressed, event=" + evt);
		System.out.println("keycode: " + evt.keyCode);

		if (evt.keyCode == 13) {
			// tambah
		} else if (evt.keyCode == 13) {
			// edit
		} else if (evt.keyCode == 13) {
			// hapus
		}
	}

}
